<?php namespace App\Models\Phm\Basedata;

use App\Models\Phm\ModelPHM;
use CodeIgniter\Database\ConnectionInterface;
use CodeIgniter\Validation\ValidationInterface;

class ModelBasedata extends ModelPHM
{
    function __construct(ConnectionInterface $db = null, ValidationInterface $validation = null)
    {
        parent::__construct($db, $validation);
    }

    public function getBasedataById($AID)
    {
        //sql语句
        $sql = "SELECT 
                    T.*
               FROM `PHM_BASEDATA` T where (   (`PKID`  =  ?)  )  ;";
        //带参数条件查询
        $rst = $this->db->query($sql,
            [$AID]
        );
        if ($rst->getNumRows() == 1) {
            return $rst->getResultArray()[0];
        } else {
            exit();
        }
    }

    //查询返回array形式
    public function getBasedataCount($AQueryData)
    {
        //查询条件
        $keyWord1 = FormatEmpty($AQueryData['KeyWord1'], '%');

        $sql = "SELECT COUNT(1) NUM FROM `PHM_BASEDATA` A WHERE 
          (
                (                                
                    ((? = '') OR (`RAW_MSG` LIKE ?)  OR ( `RAW_MSG` LIKE ? )  )
                ) 
          ) ;";
        //查看是否数量为1
        return $this->db->query($sql,
            [$keyWord1, $keyWord1, $keyWord1]
        )->getRow()->NUM;
    }

    public function getBasedata($AQueryData)
    {
        //查询条件
        $keyWord1 = FormatEmpty($AQueryData['KeyWord1'], '%');
        $sql = "SELECT 
                    A.*  
                    FROM `PHM_BASEDATA` A WHERE 
          (
                (                                
                    ((? = '') OR (`RAW_MSG` LIKE ?)  OR ( `RAW_MSG` LIKE ? )  )
                ) 
          )  ORDER BY `PKID` DESC {$AQueryData['limit']}  ;";
        //带参数条件查询
        return $this->db->query($sql,
            [$keyWord1, $keyWord1, $keyWord1]
        )->getResultArray();
    }
}